package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoStorageCheckAddVO;
import com.yunxi.sto.pojo.StoStorageCheckDetailVO;
import com.yunxi.sto.pojo.StoStorageCheckListVO;
import com.yunxi.sto.pojo.StoStorageCheckVO;
import com.yunxi.sto.service.StoStorageCheckDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 库存盘点 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-08-16
 */
@RestController
@RequestMapping("/admin/stoStorageCheck")
@Api(tags = "sto:storageCheck", description = "库存盘点接口")
public class StoStorageCheckController {
    private static final Logger logger = LoggerFactory.getLogger(StoStorageCheckController.class);

    @Autowired
    StoStorageCheckDubboService stoStorageCheckDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "checkName", value = "盘点计划名称", required = true, dataType = "String")
    })
    public ApiResult page(StoStorageCheckVO stoStorageCheckVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageCheckVO.setPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(stoStorageCheckDubboService.findPageByVO(stoStorageCheckVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(StoStorageCheckVO stoStorageCheckVO) throws Exception {
        return ResponseUtil.ok(stoStorageCheckDubboService.listByVo(stoStorageCheckVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    @ApiImplicitParam(paramType="query", name = "storageCheckId", value = "主键id", required = true, dataType = "String")
    public ApiResult load(String storageCheckId) throws Exception {
        return ResponseUtil.ok(stoStorageCheckDubboService.getById(storageCheckId));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody StoStorageCheckVO stoStorageCheckVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageCheckVO.setPartnerCode(loginInfo.getPartnerCode());
        stoStorageCheckDubboService.saveOrUpdate(stoStorageCheckVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    @ApiImplicitParam(paramType="body", name = "checkName", value = "盘点计划名称", required = true, dataType = "String")
    public ApiResult del(@RequestBody String checkName) throws Exception {
        stoStorageCheckDubboService.del(checkName);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    @ApiImplicitParam(paramType="query", name = "checkName", value = "盘点计划名称", required = true, dataType = "String")
    public ApiResult export(StoStorageCheckVO stoStorageCheckVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageCheckVO.setPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(stoStorageCheckDubboService.export(stoStorageCheckVO));
    }

    @PostMapping("/newPlan")
    @ApiOperation(value = "新增盘点计划")
    public ApiResult newPlan(@RequestBody StoStorageCheckAddVO stoStorageCheckAddVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageCheckAddVO.setPartnerCode(loginInfo.getPartnerCode());
        stoStorageCheckDubboService.newPlan(stoStorageCheckAddVO);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/checkPlanList")
    @ApiOperation(value = "盘点计划列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
    })
    public ApiResult checkPlanList(StoStorageCheckListVO stoStorageCheckListVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
//        stoStorageCheckListVO.setPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(stoStorageCheckDubboService.checkPlanList(stoStorageCheckListVO,pageNum,pageSize));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "通过VIN码获取盘点详情")
    @ApiImplicitParams(
            {@ApiImplicitParam(paramType = "query", name = "vin", value = "VIN码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "checkName", value = "计划名称", required = true, dataType = "String")
    })
    public ApiResult detail(String vin,String checkName) throws Exception {
        return ResponseUtil.ok(stoStorageCheckDubboService.detail(vin,checkName));
    }

    @PostMapping("/complete")
    @ApiOperation(value = "完成盘点")
    public ApiResult complete(@RequestBody StoStorageCheckDetailVO stoStorageCheckDetailVO,@CurrentUser LoginInfo loginInfo) throws Exception {
        stoStorageCheckDetailVO.setChecker(loginInfo.getUserCode());
        stoStorageCheckDubboService.complete(stoStorageCheckDetailVO);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/checkReport")
    @ApiOperation(value = "通过盘点计划名称获取盘点报告")
    @ApiImplicitParam(paramType = "query", name = "checkName", value = "盘点计划名称", required = true, dataType = "String")
    public ApiResult checkReport(String checkName) throws Exception {
        return ResponseUtil.ok(stoStorageCheckDubboService.checkReport(checkName));
    }

    // /admin/stoStorageStaff/getStaffList?positionCode = CK04 获取盘点人员,查询参数 checker
    // /admin/stoManage/areaList 获取库区列表

}
